package com.maxatime.controller;

import com.alibaba.fastjson.JSONObject;
import com.maxatime.common.constant.BusinessContents;
import com.maxatime.pojo.entity.SysDictType;
import com.maxatime.pojo.entity.SysRole;
import com.maxatime.pojo.entity.SysUser;
import com.maxatime.service.ISysDictTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Ssb
 * @since 2024-07-15
 */
@Controller
@RequestMapping("/sysDictType")
public class SysDictTypeController {

    @Autowired
    ISysDictTypeService isysDictTypeService;

    /**
     * @Author
     * @Description 菜单查
     * @Date
     * @Return
     * @param
     */
    @RequestMapping("/quest")
    @ResponseBody
    public Map<String,Object> quest(@RequestBody SysDictType sysDictType){
        Map<String,Object> m = new HashMap<>();
        Map<String,Object> map = isysDictTypeService.map(sysDictType);
        m.put(BusinessContents.CODE, "0000");
        m.put(BusinessContents.MSG, "交易成功");
        m.put(BusinessContents.DATA, map.get("list"));
        m.put("pageInfo", map.get("pageInfo"));
        return m;
    }
    /**
     * @Author
     * @Description 字典增
     * @Date
     * @Return
     * @param
     */
    @RequestMapping("/save")
    @ResponseBody
    public Map<String,Object> save(@RequestBody SysDictType sysDictType){
        Map<String,Object> m = new HashMap<>();
        isysDictTypeService.insertSelective(sysDictType);
        m.put(BusinessContents.CODE, "1111");
        m.put(BusinessContents.MSG, "新增成功");
        return m;
    }
    /**
     * @Author
     * @Description 字典删除
     * @Date
     * @Return
     * @param
     */
    @RequestMapping("/del")
    @ResponseBody
    public Map<String, Object> del(@RequestBody String jsonStr) {

        JSONObject jsonObj = JSONObject.parseObject(jsonStr);
        Long dictId = jsonObj.getLong("dictId");
        Map<String, Object> m = new HashMap<>();
        isysDictTypeService.deleteByPrimaryKey(dictId);
        m.put(BusinessContents.CODE, "2222");
        m.put(BusinessContents.MSG, "删除成功");
        return m;
    }
    /**
     * @Author
     * @Description 字典反显
     * @Date
     * @Return
     * @param
     */

    @RequestMapping("/find")
    @ResponseBody
    public Map<String, Object> find(@RequestBody String jsonStr) {
        JSONObject jsonObj = JSONObject.parseObject(jsonStr);
        Map<String, Object> m = new HashMap<>();
        Long dictId = jsonObj.getLong("dictId");
        SysDictType find = isysDictTypeService.find(dictId);
        m.put(BusinessContents.CODE, "3333");
        m.put(BusinessContents.MSG, "反显成功");
        m.put(BusinessContents.DATA, find);
        return m;
    }

    /**
     * @Author
     * @Description 字典修改
     * @Date
     * @Return
     * @param
     */
    @RequestMapping("/update")
    @ResponseBody
    public Map<String, Object> update(@RequestBody SysDictType sysDictType) {
        Map<String, Object> m = new HashMap<>();
        isysDictTypeService.updateByPrimaryKeySelective(sysDictType);
        m.put(BusinessContents.CODE, "4444");
        m.put(BusinessContents.MSG, "修改成功");
        return m;
    }
}
